package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingProjectController
 * @Author CWJ
 * @Date 2025-05-08  11:33
 * 护理项目控制器
 */
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController {
    @Autowired
    public NursingProjectService nursingProjectService;


    //分页查询
    @GetMapping
    public ResponseResult<PageResponse<NursingProject>> getByPage(@RequestParam(value = "name",required = false) String name,
                                                                  @RequestParam(value = "status",required = false) Integer Status,
                                                                  @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){

        PageResponse<NursingProjectVo> nursingProjectVoPageInfo = nursingProjectService.getByPage(name, Status, pageNum, pageSize);
    return ResponseResult.success(nursingProjectVoPageInfo);
    }

    //新增
    @PostMapping
    public ResponseResult<NursingProject> add(@RequestBody NursingProject nursingProject){
        nursingProjectService.add(nursingProject);
        return ResponseResult.success();
    }

    //根据id查询护理
    @GetMapping("/{id}")
    public ResponseResult<NursingProject> getById(@PathVariable("id") Integer id){
        NursingProject nursingProject = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProject);
    }

    //编辑
    @PutMapping
    public ResponseResult<NursingProject> edit(@RequestBody NursingProject nursingProject){
        nursingProjectService.edit(nursingProject);
        return ResponseResult.success();
    }

    //启用禁用
    @PutMapping("/{id}/status/{status}")
    public ResponseResult<NursingProject> editStatus(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        NursingProject nursingProject = new NursingProject();
        nursingProject.setId(id);
        nursingProject.setStatus(status);
        nursingProjectService.eq(nursingProject);
        return ResponseResult.success();
    }

    //删除
    @DeleteMapping("/{id}")
    public ResponseResult<NursingProject> delete(@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    //查询所有护理项目
    @GetMapping("/all")
    public ResponseResult<NursingProject> getAll(){
        List<NursingProject> nursingProjects = nursingProjectService.getAll();
        return ResponseResult.success(nursingProjects);
    }
}
